﻿using System;

namespace LuaNet
{
    public static class FunctionExtensions
    {
        public static Lua.lua_CFunction ToCFunction(this LuaFunction function)
        {
            var proxy = LuaCFunctionProxy.GetProxy(function);
            return proxy != null ? proxy.UnmanagedFunction : null;
        }

        public static LuaFunction ToFunction(this Lua.lua_CFunction function)
        {
            var proxy = LuaCFunctionProxy.GetProxy(function);
            return proxy != null ? proxy.ManagedFunction : null;
        }

        public static Lua.lua_KFunction ToLuaFunction(this LuaKFunction function)
        {
            var proxy = LuaKFunctionProxy.GetProxy(function);
            return proxy != null ? proxy.UnmanagedFunction : null;
        }

        public static Lua.lua_Hook ToLuaHook(this LuaHook hook)
        {
            var proxy = LuaHookProxy.GetProxy(hook);
            return proxy != null ? proxy.UnmanagedHook : null;
        }

        public static LuaHook ToHook(this Lua.lua_Hook hook)
        {
            var proxy = LuaHookProxy.GetProxy(hook);
            return proxy != null ? proxy.ManagedHook : null;
        }

        public static Lua.lua_Reader ToLuaReader(this LuaReader reader)
        {
            var proxy = LuaReaderProxy.GetProxy(reader);
            return proxy != null ? proxy.UnmanagedReader : null;
        }

        public static Lua.lua_Writer ToLuaWriter(this LuaWriter writer)
        {
            var proxy = LuaWriterProxy.GetProxy(writer);
            return proxy != null ? proxy.UnmanagedWriter : null;
        }
    }
}
